package org.keyintegrity.webbeans.metadata.store.xmlstream;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

import org.keyintegrity.webbeans.metadata.BeanMetadata;
import org.keyintegrity.webbeans.metadata.FieldMetadata;

@XmlType
public class XmlBeanMetadata extends BeanMetadata {
    
    /**
     * 
     */
    private static final long serialVersionUID = 3677024654931772045L;
    
    private List<XmlFieldMetadata> xmlFieldsMetadata;
    
    public void setXmlFieldsMetadata(List<XmlFieldMetadata> xmlFieldsMetadata) {
        this.fieldsMetadata = new ArrayList<FieldMetadata>();
        for (XmlFieldMetadata metadata : xmlFieldsMetadata) {
            fieldsMetadata.add(metadata);
        }
    }

    public XmlBeanMetadata() {
        // TODO Auto-generated constructor stub
    }
    
    public XmlBeanMetadata(BeanMetadata bm) {
        this.associatedClass = bm.getAssociatedClass();
        this.fieldsMetadata = bm.getFieldsMetadata();
    }
    
    @Override
    protected FieldMetadata newFieldMetadata() {
        return new XmlFieldMetadata();
    }

    @XmlElement
    public List<XmlFieldMetadata> getXmlFieldsMetadata() {
        if (xmlFieldsMetadata == null) {
            xmlFieldsMetadata = new ArrayList<XmlFieldMetadata>();
            for (FieldMetadata fieldMetadata : getFieldsMetadata()) {
                XmlFieldMetadata xfm = XmlFieldMetadata.fromFieldMetadata(fieldMetadata);
                xmlFieldsMetadata.add(xfm);
            }
        }
        return xmlFieldsMetadata;
    }

}
